package com.amazon.dao;

import com.amazon.bo.BrowseTree;
import com.amazon.dao.base.BaseDao;
import org.hibernate.query.Query;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class BrowseTreeDao extends BaseDao<BrowseTree> {

    //供应链产品列表
    public List<BrowseTree> getBrowseTreeList(String conn, final int page, final int pageSize) {
        List<BrowseTree> results = execute(session -> (List<BrowseTree>) session
                .createNativeQuery("SELECT * FROM browse_tree "
                        +conn+" order by id  ", BrowseTree.class)
                .setFirstResult((page - 1) * pageSize)
                .setMaxResults(pageSize)
                .getResultList());
        return results != null ? results : new ArrayList<BrowseTree>();
    }
    //更新中文路径
    public boolean saveChPath(BrowseTree b){
        BrowseTree old=getById(b.getId());
        if(old!=null){
            old.setChPath(b.getChPath());
            old.setKeyWords(b.getKeyWords());
            update(old);
            return true;
        }
        else{
            return false;
        }
    }
    //详情
    public BrowseTree getAmazonInfoByEnid(String enid){
        BrowseTree kw=execute(session ->
                session.createNativeQuery("SELECT * FROM browse_tree WHERE en_id=:en_id",BrowseTree.class)
                        .setParameter("en_id",enid).uniqueResult());
        return kw;
    }


}
